package com.campusify.controller;


import com.campusify.compents.ApiResponse;
import com.campusify.compents.PageResult;

import com.campusify.pojo.Sort;
import com.campusify.service.SortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * controller
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/sort")
public class SortController {

	@Autowired
	private SortService sortService;
	
	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findAll")
	public List<Sort> findAll(){			
		return sortService.findAll();
	}
	
	
	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findPage")
	public PageResult  findPage(int page,int rows){			
		return sortService.findPage(page, rows);
	}
	
	/**
	 * 增加
	 * @param sort
	 * @return
	 */
	@RequestMapping("/add")
	public ApiResponse add(@RequestBody Sort sort){
		try {
			sortService.add(sort);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}
	
	/**
	 * 修改
	 * @param sort
	 * @return
	 */
	@RequestMapping("/update")
	public ApiResponse update(@RequestBody Sort sort){
		try {
			sortService.update(sort);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}	
	
	/**
	 * 获取实体
	 * @param id
	 * @return
	 */
	@RequestMapping("/findOne")
	public Sort findOne(Integer sortID){
		return sortService.findOne(sortID);		
	}
	
	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	public ApiResponse delete(Integer [] sortIDs){
		try {
			sortService.delete(sortIDs);
			return ApiResponse.success(null); 
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}
	
		/**
	 * 查询+分页
	 * @param brand
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/search")
	public PageResult search(@RequestBody Sort sort, int page, int rows  ){
		return sortService.findPage(sort, page, rows);		
	}
	
}
